<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>云API</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../css/style.css"/>
    <style>
    body{
      overflow:hidden;
      position:fixed;
      left:0;
      top:1.5rem;
    }
    .header{
          width: 100%;
          height: 2.5rem;
          line-height: 2.5rem;
          padding: 0.5rem 0rem;
          text-align: center;
          position: fixed;
          top:2.5rem;
          background-color: #fff;
      }

    .header ul {
        width: 100%;
        margin: 0 auto;
        display: flex;
        justify-content: space-between;
    }

    .header ul li {
        width: 30%;
        text-align: center;
        float: left;
        font-family: '宋体'
    }

    .header ul li a {
        color: black;
        text-decoration: none;
        font-weight: bold;
        font-size: 1.2rem;
    }
  .inp{
    width: 80%;
    margin: 3rem auto 0rem;
    margin-top:35%;

  }
  .inp input{
    outline: none;
    width: 100%;
    height: 4rem;
    color: black;
    line-height: 4rem;
    font-size: 1.3rem;
    border-bottom: 1px solid #ccc;
  }
  #name{
    background: url(../image/u14.png) center right;
    background-size: 7% 34%;
    background-repeat: no-repeat;
  }
  #pwd{
    background: url(../image/u15.png) center right;
    background-size: 7% 34%;
    background-repeat: no-repeat;
  }
  .log{
    width: 100%;
    height: 3.5rem;
    background-color: #40cccc;
    color: #fff;
    line-height: 3.5rem;
    text-align: center;
    margin-top: 4rem;
    font-size: 1.2rem;
    border-radius: 2rem;
    letter-spacing:0.1rem;
  }
  .p{
    width: 100%;
    height: 1rem;
    text-align: center;
    line-height: 1rem;
    margin-top: 0.8rem;
  }
  .p1{
    position: absolute;
    top:-0.5rem;
    padding: 0rem 0.8rem;
    left: 37%;
    height: 1rem;
    text-align: center;
    line-height: 1rem;
    background-color: #fff;
  }
  .footer{
    width: 80%;
    position: fixed;
    bottom:1rem;
    left: 10%;
    border-top:1px solid #ccc;
  }
  .footer_img{
    width: 80%;
    margin: 1rem auto;
    display: flex;
    justify-content: space-between;
  }
  .img{
    width: 20%;
    height: 10%;
  }
  .img img{
    width: 100%;
    height: 100%;
  }
    </style>
</head>
<body>
  <div class="header">
      <ul>
          <!-- <li><a href="#">取消</a></li> -->
          <li onclick="out_at()"><a href="#">取消</a></li>
          <li onclick=""><a href="#" id="a"></a>
          </li>

      </ul>
  </div>

<div class="inp">
  <input type="text" name="" placeholder="新密码" id="pwd">
  <input type="password" name="" placeholder="重复密码" id="pwd1">
  <div class="log" onclick="login_at()">确认修改</div>
  <p class="p" onclick="openwin('get_pass')">忘记了密码?</p>
</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.3.js"></script>
<script type="text/javascript">
var userinfo = $api.getStorage('userinfo');
var type = 0
apiready = function() {
  api.addEventListener({
      name:'user_register',
      extra:{
          threshold:0
      }
  }, function(ret, err){
      api.closeWin({

      });


        //alert( JSON.stringify( ret ) );
  });

  api.addEventListener({
      name:'user_login',
      extra:{
          threshold:0
      }
  }, function(ret, err){
      api.closeWin({

      });


        //alert( JSON.stringify( ret ) );
  });
}
function out_at() {
  api.closeWin({

  });
}
function login_at() {

    var pwd = document.getElementById('pwd').value
    var pwd1 = document.getElementById('pwd1').value
    if(pwd!=pwd1||pwd==''||pwd1==''){
      msgcode('输入不正确')
      return false;
    }


    api.ajax({
        url: SITE_URL+'user_api/user/up_pass',
        method: 'post',
        data: {
            values: {
                pwd:pwd,
                user_id:userinfo.id
            }
        }
    },function(ret, err){
        if (ret) {
          if(ret.error==200){
            alert('请重新登录')
            // $api.setStorage('userinfo', ret.data);
            $api.rmStorage('userinfo');
            api.sendEvent({
                name: 'login_out',
            });
            api.openFrame({
                name: 'user_login',
                url: './user_login.html',
                rect: {
                    x: 0,
                    y: 0,
                    w: 'auto',
                    h: 'auto'
                }
            });
            // api.sendEvent({
            //     name: 'user_login',
            // });

          }else if(ret.error==250){
            msgcode('换一个密码吧')
          }else{
            msgcode('稍后再试')
          }
            //alert( JSON.stringify( ret ) );
        } else {
          msgcode('请检查网络连接')
            alert( JSON.stringify( err ) );
        }
    });

}

</script>
</html>
